from datetime import datetime
from .. import db

class Pathogen(db.Model):
    __tablename__ = 'pathogens'
    
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(100), nullable=False)
    type = db.Column(db.String(20), nullable=False)
    isolation_date = db.Column(db.DateTime, nullable=False)
    isolation_location = db.Column(db.String(200), nullable=False)
    latitude = db.Column(db.Float)
    longitude = db.Column(db.Float)
    gene_sequence = db.Column(db.Text)
    
    created_at = db.Column(db.DateTime, default=datetime.utcnow)
    updated_at = db.Column(db.DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
    created_by = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)
    
    # 关联用户
    creator = db.relationship('User', backref=db.backref('pathogens', lazy=True)) 